package app1.rapidsquare.com.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.ViewGroup;

import java.util.Arrays;
import java.util.List;

import app1.rapidsquare.com.fragment.AgileDayFragment;
import app1.rapidsquare.com.fragment.ContactFragment;
import app1.rapidsquare.com.fragment.EventFragment;
import app1.rapidsquare.com.fragment.ProfileFragment;

/**
 * Created by Hikmat on 07.08.2014.
 */
public class AgileFragmentPagerAdapter extends FragmentStatePagerAdapter {

    private List<Class<? extends Fragment>> mViewPagerFragment = Arrays.asList(ContactFragment.class, EventFragment.class, AgileDayFragment.class, ProfileFragment.class);
    private Context mContext;

    public AgileFragmentPagerAdapter(Context context, FragmentManager fm) {
        super(fm);
        mContext = context;
    }

    @Override
    public Fragment getItem(int position) {
        if (position < mViewPagerFragment.size() && position >= 0) {
            return Fragment.instantiate(mContext, mViewPagerFragment.get(position).getName());
        }

        return Fragment.instantiate(mContext, mViewPagerFragment.get(0).getName());
    }

    @Override
    public int getCount() {
        return mViewPagerFragment.size();
    }

    public int getPosition(Class<?> fragment) {
        return mViewPagerFragment.indexOf(fragment);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        return super.instantiateItem(container, position);
    }
}
